
const resolvers = {
  Query: {
    async users (p, args, { dataSources: { users } }) {
      const data = await users.model.find();
      return data;
    }
  },
  Mutation: {
    async createUser (p, args, { dataSources: { users }}) {
      const user = new users.model(args.user);
      await user.save();
      return user;
    },
    async updateUser (p, args, { dataSources: { users }}) {
      const id = args.id;
      const user = await users.model.findByIdAndUpdate(id, args.user);
      return user;
    },
    async deleteUser (p, args, { dataSources: { users }}) {
      const id = args.id;
      const user = await users.model.findByIdAndRemove(id);
      return true;
    }
  }
}

module.exports = resolvers;
